function thisrender(this, hFig, pos)
%THISRENDER Render the window Management component

%   Author(s): V.Pellissier
%   Copyright 1988-2005 The MathWorks, Inc.
%   $Revision: 1.3.4.4 $  $Date: 2005/12/22 19:04:41 $

if nargin < 3 , pos =[]; end
if nargin < 2 , hFig = gcf; end

sz = gui_sizes(this);
if isempty(pos)
    pos = [10 10 413 212]*sz.pixf;
end

cbs = callbacks(this);

hPanel = uipanel('Parent', hFig, ...
    'Units', 'Pixels', ...
    'Position', pos, ...
    'Visible', 'Off', ...
    'Title', xlate('Window List'));

hLayout = siglayout.gridbaglayout(hPanel);

set(hLayout, ...
    'HorizontalGap',     15, ...
    'VerticalWeights',   [0 0 0 0 0 1], ...
    'HorizontalWeights', [1 0]);

h.text = uicontrol(hPanel, 'style', 'text', ...
    'Enable', 'on', ...
    'horizontalAlignment', 'left', ...
    'string', 'Select windows to display:');

hLayout.add(h.text, 1, [1 2], ...
    'MinimumWidth', 100*sz.pixf, ...
    'MinimumHeight', sz.uh, ...
    'TopInset', 20*sz.pixf, ...
    'Fill', 'Horizontal');

h.listbox = uicontrol(hPanel, 'style', 'listbox',...
    'max', 2, ...
    'callback', cbs.set_selection);

hLayout.add(h.listbox, 2:6, 1, ...
    'Fill', 'Both', ...
    'BottomInset', 10*sz.pixf);

actionStrs = {'Add a new window', ...
    'Copy window', ...
    'Save to workspace', ...
    'Delete'};

tags = {'addwindow', ...
        'copywindow', ...
        'savewindow', ...
        'delete'};

cb = callbacks(this);
cbs = {cb.addnewwin, cb.copywindow, cb.save_selection, cb.delete_selection};

% Render buttons from bottom to top
for n=1:length(actionStrs),

    h.pbs(n)=uicontrol(hPanel, ...
        'style',    'pushbutton',...
        'string',   actionStrs{n},...
        'tag',      tags{n},...
        'Interruptible', 'Off', ...
        'BusyAction', 'cancel', ...
        'callback', cbs{n});
    
    hLayout.add(h.pbs(n), 1+n, 2, ...
        'MinimumWidth', 123*sz.pixf, ...
        'BottomInset', 10*sz.pixf, ...
        'TopInset', 10*sz.pixf, ...
        'MinimumHeight', sz.bh);
end

% Store handles in object
set(this, 'Handles', h, ...
    'FigureHandle', hFig, ...
    'Container', hPanel);

% Install listeners
installListeners(this);

% Add context-sensitive help
cshelpcontextmenu(this, 'wintool_winmanagement_frame', 'WinTool');

% Fire listeners to sync the GUI state with the object properties
window_list_listener(this);
selection_listener(this);

%---------------------------------------------------------------------
function installListeners(this)

% Create the listeners
listener    = handle.listener(this, this.findprop('Window_list'), ...
    'PropertyPostSet', @window_list_listener);

% Set this to be the input argument to these listeners
set(listener,'CallbackTarget', this);

% Save the listeners
set(this, 'WhenRenderedListeners', listener);


% [EOF]
